function [obsdata]= gendataforBCCCE(k, pcntgs)


CUTOFF=2;
data=drawhalfmoon();
N=size(data,1);
datalabel=ones(N/2,1);
datalabel=[datalabel; 2*ones(N/2,1)];

% fp=fopen('halfmoontruelabel.txt','w+');
% for i=1:size(data,1)
%   if(datalabel(i)==1)
%    fprintf(fp,'+1\n');
%   else
%    fprintf(fp,'-1\n');
%   end 
% end
% fclose(fp);


% fp1=fopen('halfmoonaccs.txt','w+');


% figure (1), 
% gscatter(data(:,1), data(:,2), datalabel,'bb','o+'),title('Original Data'),xlabel('x'), ylabel('y');


%[1:1:10];
MAXCOUNT=1;
alpha=0.01;
lambda=0.1;
numiter=50;

fp2=fopen('hmavgacc.txt','w+');
fp3=fopen('hmmaxacc.txt','w+');
fp4=fopen('hmC3Eacc.txt','w+');




for pcntcnt=1:size(pcntgs,2)

    
    
maxacc=[];
accuracyCCCE=[];


pcntcnt    
% response=input('complete?');
% 
% while(response==0)
% 
% disp('previous alpha:'); disp(alpha);    
% alpha=input('Enter alpha: ');
    
for count=1:MAXCOUNT   
count

trainsize=round((pcntgs(pcntcnt)/100)*N);
testsize=N-trainsize;

Xvtrainindex=[];

for i=1:trainsize
    
 temp=0;
 while(temp==0 || isempty(find(Xvtrainindex==temp))==0)
 temp = round((N-1)*rand)+1;
 end
 Xvtrainindex(i) = temp;
 
end

Xvtrain     = data(Xvtrainindex',:);
Yvtrain     = datalabel(Xvtrainindex');
% figure (2), 
% gscatter(Xvtrain(:,1), Xvtrain(:,2), Yvtrain),title('Training Data'),xlabel('x'), ylabel('y');

dataindex   = [1:N];
Xvtestindex = setdiff(dataindex, Xvtrainindex);
Xvtest      = data(Xvtestindex',:);
Yvtesttrue  = datalabel(Xvtestindex);

str1=num2str(pcntgs(pcntcnt));
str2=num2str(count);
str3='hmworksetlabel';
str4= strcat(str1,'_',str2,'_',str3,'.txt');

fp1=fopen(str4,'w+');
for i=1:size(data,1)
 if(isempty(find(Xvtrainindex==i))~=1)
  if(datalabel(i)==1)
   fprintf(fp1,'+1\n');
  else
   fprintf(fp1,'-1\n');
  end 
 else
  fprintf(fp1,'0\n');
 end
end
fclose(fp1);





[YvtestDT, accuracyDT]   = DTclassify (Xvtrain, Yvtrain, Xvtest, Yvtesttrue);
[YvtestGLM, accuracyGLM] = genlogit (Xvtrain, Yvtrain, Xvtest, Yvtesttrue);
[Yvtestlda, accuracylda] = ldaclassify (Xvtrain, Yvtrain, Xvtest, Yvtesttrue);
piSet=[YvtestDT+YvtestGLM+Yvtestlda]/3;  
[tempgarbage,tempSet]=max(piSet,[],2);
avgacc(count)=(100/size(tempSet,1))*size(find(tempSet==Yvtesttrue),1);
avgacc(count)


% Data for BC3E

%%%%%%%%%%%%%
CDT   = [[1:k]*YvtestDT']';
tempC = [];
tempC = zeros(testsize,k);
tempC = tempC';
tempC(k*[0:testsize-1]'+CDT)=1;
tempC = tempC';
dataw1(1).w=tempC;

[garbageval,dataBGCM(:,1)]=max(YvtestDT');

%%%%%%%%%%%%%%
CGLM  = [[1:k]*YvtestGLM']';
tempC = [];
tempC = zeros(testsize,k);
tempC = tempC';
tempC(k*[0:testsize-1]'+CGLM)=1;
tempC = tempC';
dataw1(2).w=tempC;

[garbageval,dataBGCM(:,2)]=max(YvtestGLM');

%%%%%%%%%%%%%%%
Clda  = [[1:k]*Yvtestlda']';
tempC = [];
tempC = zeros(testsize,k);
tempC = tempC';
tempC(k*[0:testsize-1]'+Clda)=1;
tempC = tempC';
dataw1(3).w=tempC;

[garbageval,dataBGCM(:,3)]=max(Yvtestlda');

%%%%%%%%%%%%%%


accs= [accuracyDT; accuracyGLM; accuracylda];
maxacc(count) = max(accs);
%% figure (2), 
%% gscatter(Xvtest(:,1), Xvtest(:,2), T),title('clustering result');

CUTOFFmat=[CUTOFF:CUTOFF+8];
SSet=zeros(testsize,testsize);

for i=1:size(CUTOFFmat,2)
    
    Clnum = CUTOFFmat(i);
    T     = CLUSTERDATA(Xvtest,Clnum);
    
    dataBGCM(:,3+i)=T;

    % Data for BC3E
    %%%%%%%%%%%%%%%    
    tempT = zeros(testsize,size(unique(T),1));
    tempT = tempT';
    tempT(size(unique(T),1)*[0:testsize-1]'+T)=1;
    tempT = tempT';
    
    dataw2(i).w=tempT;
    %%dataw1(i).w=tempT;
    
    %% for debugging
    
%     TL     = max(T)-T;
%     tempTL = zeros(testsize,size(unique(TL),1));
%     tempTL = tempTL';
%     tempTL(size(unique(TL),1)*[0:testsize-1]'+TL)=1;
%     tempTL = tempTL'; 
%     
%     dataw1(i).w=tempTL;
    
    %% for debugging ends
    %%%%%%%%%%%%%%%
    
    
    temp2 = zeros(testsize,Clnum);
    temp2 = temp2';
    temp3 = T+Clnum*[0:testsize-1]';
    temp2(temp3)=1;
    temp2 = temp2';
    SSet  = SSet+temp2*temp2';

end

SSet  = SSet/size(CUTOFFmat,2);


%[accuracyCCCE(count),CCCESet]=call_CCCE(piSet, SSet, Yvtesttrue, alpha, lambda, numiter);
%accuracyCCCE(count)


% siz=10;

% figure (1), 
% gscatter(Xvtest(:,1), Xvtest(:,2), tempSet,'br','*+', siz),xlabel('x'), ylabel('y'), legend('class 1','class 2');
% 
% figure (2), 
% gscatter(Xvtest(:,1), Xvtest(:,2), CCCESet,'br','*+', siz),xlabel('x'), ylabel('y'), legend('class 1','class 2');

end


for i=1:size(avgacc,2)
    fprintf(fp2,'%f ',avgacc(i));
end
fprintf(fp2,'\n');

for i=1:size(maxacc,2)
    fprintf(fp3,'%f ',maxacc(i));
end
fprintf(fp3,'\n');

for i=1:size(accuracyCCCE,2)
    fprintf(fp4,'%f ',accuracyCCCE(i));
end
fprintf(fp4,'\n');

avgaccavg=mean(avgacc);
avgaccstd=std(avgacc);

maxaccavg=mean(maxacc);
maxaccstd=std(maxacc);

accuracyCCCEavg=mean(accuracyCCCE);
accuracyCCCEstd=std(accuracyCCCE);

end

fclose(fp2);
fclose(fp3);
fclose(fp4);



obsdata.dataw1    = dataw1;
obsdata.dataw2    = dataw2;
obsdata.truelabel = Yvtesttrue;
obsdata.r1        = 3;
obsdata.r2        = size(CUTOFFmat,2);
obsdata.dataBGCM  = dataBGCM;

end

